package com.tiku.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableWebMvc

@EnableOpenApi
public class SwaggerConfig {

    @Bean
    public Docket api() {

        ParameterBuilder tokenPar = new ParameterBuilder();
        List<Parameter> pars = new ArrayList<>();
        tokenPar.name("token").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
        pars.add(tokenPar.build());
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                .groupName("mike")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.tiku.controller"))
                .paths(PathSelectors.any())
                .build().globalOperationParameters(pars)
                ;
    }

    private ApiInfo apiInfo() {
        return new ApiInfo(
                "你的项目 API 文档",
                "题库",
                "1.0",
                "服务条款链接",
                new Contact("低调", "www.baidu.com", "1667301172@qq.com"),
                "许可证名称",
                "许可证链接",
                new ArrayList());
    }
}